const events = require("events");
const { pid } = require("process");
// const EventEmitter = events.EventEmitter;
const utils = require('util');

function Radio(radioName, radioTime) {
    // this.emitter = new events.EventEmitter(this);
    this.radioName = radioName;
    this.radioTime = radioTime;
    // EventEmitter.call(this);//执行EventEmitter,调用主体是this
    //this指代实例化对象
    // this.on("play", () => {
    //     console.log("opened");
    // },
    //     this.on("stop", () => {
    //         console.log("closed");
    //     })
    // )

}
utils.inherits(Radio, events.EventEmitter);
Radio.prototype.play = function () {
    console.log(this.radioName + this.radioTime + "opened");
    setTimeout(function () { console.log('lalala...'); process.kill(process.pid, 'SIGHUP') }, 2000)
}
Radio.prototype.close = function () {
    process.on('SIGHUP', () => {
        console.log(this.radioName + this.radioTime + "closed");
    })

}
module.exports = Radio;
    // Radio.prototype = EventEmitter.prototype;
// let radio = new Radio();
// radio.emit("play");
// radio.emit("stop");
// console.log(radio);



